home *** CD-ROM | disk | FTP | other *** search
- /*
- * (c) Copyright 1993, 1994, Silicon Graphics, Inc.
- * ALL RIGHTS RESERVED
- * Permission to use, copy, modify, and distribute this software for
- * any purpose and without fee is hereby granted, provided that the above
- * copyright notice appear in all copies and that both the copyright notice
- * and this permission notice appear in supporting documentation, and that
- * the name of Silicon Graphics, Inc. not be used in advertising
- * or publicity pertaining to distribution of the software without specific,
- * written prior permission.
- *
- * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
- * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
- * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
- * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
- * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
- * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
- * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
- * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
- * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN
- * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
- * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
- *
- * US Government Users Restricted Rights
- * Use, duplication, or disclosure by the Government is subject to
- * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
- * (c)(1)(ii) of the Rights in Technical Data and Computer Software
- * clause at DFARS 252.227-7013 and/or in similar or successor
- * clauses in the FAR or the DOD or NASA FAR Supplement.
- * Unpublished-- rights reserved under the copyright laws of the
- * United States. Contractor/manufacturer is Silicon Graphics,
- * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311.
- *
- * OpenGL(TM) is a trademark of Silicon Graphics, Inc.
- */
- #include <GL/glu.h>
- #include <GL/glx.h>
- #include <X11/keysym.h>
- #include <math.h>
- #include <sys/time.h>
- #include <stdio.h>
- #include "objects.h"
-
- #define X 0
- #define Y 1
- #define Z 2
-
- #ifndef TRUE
- #define TRUE 1
- #endif
- #ifndef FALSE
- #define FALSE 0
- #endif
-
- #define DEG *M_PI/180.0
- #define RAD *180.0/M_PI
-
- float move_speed; /* Spline distance per second */
-
- Display *dpy;
- Window window;
-
- int multisample = 0; /* Antialias polygons? */
- int doublebuffer = 1; /* Doublebuffer? */
- int stereo = 0; /* Use stereo? */
-
-
- #define SPEED_SLOW 0.2 /* Spline distances per second */
- #define SPEED_MEDIUM 0.4
- #define SPEED_FAST 0.7
- #define SPEED_SUPER_FAST 1.0
-
- #define O_NOMS 7
- #define O_4MS 8
- #define O_8MS 9
- #define O_16MS 10
-
- static int RGBA_SB_attributes[] = {
- GLX_RGBA,
- GLX_RED_SIZE, 1,
- GLX_GREEN_SIZE, 1,
- GLX_BLUE_SIZE, 1,
- GLX_DEPTH_SIZE, 1,
- None,
- };
-
- static int RGBA_SB_ST_attributes[] = {
- GLX_RGBA,
- GLX_STEREO,
- GLX_RED_SIZE, 1,
- GLX_GREEN_SIZE, 1,
- GLX_BLUE_SIZE, 1,
- GLX_DEPTH_SIZE, 1,
- None,
- };
-
- static int RGBA_DB_attributes[] = {
- GLX_RGBA,
- GLX_RED_SIZE, 1,
- GLX_GREEN_SIZE, 1,
- GLX_BLUE_SIZE, 1,
- GLX_DOUBLEBUFFER,
- GLX_DEPTH_SIZE, 1,
- None,
- };
-
- static int RGBA_DB_ST_attributes[] = {
- GLX_RGBA,
- GLX_STEREO,
- GLX_RED_SIZE, 1,
- GLX_GREEN_SIZE, 1,
- GLX_BLUE_SIZE, 1,
- GLX_DOUBLEBUFFER,
- GLX_DEPTH_SIZE, 1,
- None,
- };
-
- float idmat[4][4] = {
- {1.0, 0.0, 0.0, 0.0},
- {0.0, 1.0, 0.0, 0.0},
- {0.0, 0.0, 1.0, 0.0},
- {0.0, 0.0, 0.0, 1.0},
- };
-
- float light1_ambient[] = { 0.0,0.0,0.0,1.0 };
- float light1_lcolor[] = { 1.0,1.0,1.0,1.0 };
- float light1_position[] = { 0.0,1.0,0.0,0.0 };
-
- float light2_ambient[] = { 0.0,0.0,0.0,1.0 };
- float light2_lcolor[] = { 0.3,0.3,0.5,1.0 };
- float light2_position[] = { -1.0,0.0,0.0,0.0 };
-
- float light3_ambient[] = { 0.2,0.2,0.2,1.0 };
- float light3_lcolor[] = { 0.2,0.2,0.2,1.0 };
- float light3_position[] = { 0.0,-1.0,0.0,0.0 };
-
- float lmodel_LVW[] = { 0.0 };
- float lmodel_ambient[] = { 0.3,0.3,0.3,1.0 };
- float lmodel_TWO[] = { GL_TRUE };
-
- float mat_logo_ambient[] = {0.1, 0.1, 0.1, 1.0};
- float mat_logo_diffuse[] = {0.5, 0.4, 0.7, 1.0};
- float mat_logo_specular[] = {1.0, 1.0, 1.0, 1.0};
- float mat_logo_shininess[] = {30.0};
-
- float mat_holder_base_ambient[] = {0.0, 0.0, 0.0, 1.0};
- float mat_holder_base_diffuse[] = {0.6, 0.6, 0.6, 1.0};
- float mat_holder_base_specular[] = {0.8, 0.8, 0.8, 1.0};
- float mat_holder_base_shininess[] = {30.0};
-
- float mat_holder_rings_ambient[] = { 0.0,0.0,0.0,1.0 };
- float mat_holder_rings_diffuse[] = { 0.9,0.8,0.0,1.0 };
- float mat_holder_rings_specular[] = { 1.0,1.0,1.0,1.0 };
- float mat_holder_rings_shininess[] = { 30.0 };
-
- float mat_hemisphere_ambient[] = {0.0, 0.0, 0.0,1.0 };
- float mat_hemisphere_diffuse[] = {1.0, 0.2, 0.2,1.0 };
- float mat_hemisphere_specular[] = {0.5, 0.5, 0.5,1.0 };
- float mat_hemisphere_shininess[] = {20.0};
-
- GLubyte stipple[32*32];
-
- typedef float vector[3];
- typedef vector parameter[4];
-
- /*
- * Function definitions
- */
- void initialize(char *title);
- void resize_window();
- void build_table();
- parameter *calc_spline_params(vector *ctl_pts, int n);
- void calc_spline(vector v, parameter *params, float current_time);
- void normalize(vector v);
- float dot(vector v1, vector v2);
- void draw_table();
- void draw_logo_shadow();
- void draw_hemisphere();
- void draw_logo();
- void draw_under_table();
- void draw_i();
- void draw_d();
- void draw_e();
- void draw_a();
- void draw_s();
- void draw_n();
- void draw_m();
- void draw_o();
- void draw_t();
-
- init_materials() {
- int x, y;
-
- /* Stipple pattern */
- for (y = 0; y < 32; y++)
- for (x = 0; x < 4; x++)
- stipple[y * 4 + x] = (y % 2) ? 0xaa : 0x55;
-
- glNewList(MAT_LOGO, GL_COMPILE);
- glMaterialfv(GL_FRONT, GL_AMBIENT, mat_logo_ambient);
- glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_logo_diffuse);
- glMaterialfv(GL_FRONT, GL_SPECULAR, mat_logo_specular);
- glMaterialfv(GL_FRONT, GL_SHININESS, mat_logo_shininess);
- glEndList();
-
- glNewList( MAT_HOLDER_BASE, GL_COMPILE);
- glMaterialfv(GL_FRONT, GL_AMBIENT, mat_holder_base_ambient);
- glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_holder_base_diffuse);
- glMaterialfv(GL_FRONT, GL_SPECULAR, mat_holder_base_specular);
- glMaterialfv(GL_FRONT, GL_SHININESS, mat_holder_base_shininess);
- glEndList();
-
- glNewList(MAT_HOLDER_RINGS, GL_COMPILE);
- glMaterialfv(GL_FRONT, GL_AMBIENT, mat_holder_rings_ambient);
- glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_holder_rings_diffuse);
- glMaterialfv(GL_FRONT, GL_SPECULAR, mat_holder_rings_specular);
- glMaterialfv(GL_FRONT, GL_SHININESS, mat_holder_rings_shininess);
- glEndList();
-
- glNewList(MAT_HEMISPHERE, GL_COMPILE);
- glMaterialfv(GL_FRONT, GL_AMBIENT, mat_hemisphere_ambient);
- glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_hemisphere_diffuse);
- glMaterialfv(GL_FRONT, GL_SPECULAR, mat_hemisphere_specular);
- glMaterialfv(GL_FRONT, GL_SHININESS, mat_hemisphere_shininess);
- glEndList();
-
- }
-
- void init_lights() {
- static float ambient[] = { 0.1, 0.1, 0.1, 1.0 };
- static float diffuse[] = { 0.5, 1.0, 1.0, 1.0 };
- static float position[] = { 90.0, 90.0, 150.0, 0.0 };
-
- glLightfv(GL_LIGHT0, GL_AMBIENT, ambient);
- glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse);
- glLightfv(GL_LIGHT0, GL_POSITION, position);
-
- glLightfv (GL_LIGHT1, GL_AMBIENT, light1_ambient);
- glLightfv (GL_LIGHT1, GL_SPECULAR, light1_lcolor);
- glLightfv (GL_LIGHT1, GL_DIFFUSE, light1_lcolor);
- glLightfv (GL_LIGHT1, GL_POSITION, light1_position);
-
- glLightfv (GL_LIGHT2, GL_AMBIENT, light2_ambient);
- glLightfv (GL_LIGHT2, GL_SPECULAR, light2_lcolor);
- glLightfv (GL_LIGHT2, GL_DIFFUSE, light2_lcolor);
- glLightfv (GL_LIGHT2, GL_POSITION, light2_position);
-
- glLightfv (GL_LIGHT3, GL_AMBIENT, light3_ambient);
- glLightfv (GL_LIGHT3, GL_SPECULAR, light3_lcolor);
- glLightfv (GL_LIGHT3, GL_DIFFUSE, light3_lcolor);
- glLightfv (GL_LIGHT3, GL_POSITION, light3_position);
-
- glLightModelfv (GL_LIGHT_MODEL_LOCAL_VIEWER, lmodel_LVW);
- glLightModelfv (GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);
- }
-
- short dev, val;
-
- float current_time=0.0;
- float hold_time=0.0; /* Used when auto-running */
-
- float tmplight[] = {
- GL_POSITION, 0.0, 0.0, 0.0, 0.0,
- };
-
- GLfloat tv[4][4] = {
- {1.0, 0.0, 0.0, 0.0},
- {0.0, 1.0, 0.0, -1.0},
- {0.0, 0.0, 1.0, 0.0},
- {0.0, 0.0, 0.0, 0.0},
- };
-
- #define TABLERES 12
-
- float pcr, pcg, pcb, pca;
-
- vector table_points[TABLERES+1][TABLERES+1];
- int tablecolors[TABLERES+1][TABLERES+1];
-
- vector paper_points[4] = {
- {-0.8, 0.0, 0.4},
- {-0.2, 0.0, -1.4},
- {1.0, 0.0, -1.0},
- {0.4, 0.0, 0.8},
- };
-
- float dot(vector, vector);
-
- #define TIME 15
- #define START_TIME 0.6
-
- vector light_pos_ctl[] = {
-
- {0.0, 1.8, 0.0},
- {0.0, 1.8, 0.0},
- {0.0, 1.6, 0.0},
-
- {0.0, 1.6, 0.0},
- {0.0, 1.6, 0.0},
- {0.0, 1.6, 0.0},
- {0.0, 1.4, 0.0},
-
- {0.0, 1.3, 0.0},
- {-0.2, 1.5, 2.0},
- {0.8, 1.5, -0.4},
- {-0.8, 1.5, -0.4},
-
- {0.8, 2.0, 1.0},
- {1.8, 5.0, -1.8},
- {8.0, 10.0, -4.0},
- {8.0, 10.0, -4.0},
- {8.0, 10.0, -4.0},
- };
-
- vector logo_pos_ctl[] = {
-
- {0.0, -0.5, 0.0},
-
- {0.0, -0.5, 0.0},
- {0.0, -0.5, 0.0},
-
- {0.0, -0.5, 0.0},
- {0.0, -0.5, 0.0},
- {0.0, -0.5, 0.0},
- {0.0, 0.0, 0.0},
-
- {0.0, 0.6, 0.0},
- {0.0, 0.75, 0.0},
- {0.0, 0.8, 0.0},
- {0.0, 0.8, 0.0},
-
- {0.0, 0.5, 0.0},
- {0.0, 0.5, 0.0},
- {0.0, 0.5, 0.0},
- {0.0, 0.5, 0.0},
- {0.0, 0.5, 0.0},
- };
-
-
- vector logo_rot_ctl[] = {
-
- {0.0, 0.0, -18.4},
-
- {0.0, 0.0, -18.4},
- {0.0, 0.0, -18.4},
-
- {0.0, 0.0, -18.4},
- {0.0, 0.0, -18.4},
- {0.0, 0.0, -18.4},
- {0.0, 0.0, -18.4},
- {0.0, 0.0, -18.4},
-
- /* {90.0, 0.0, -90.0},
- {180.0, 180.0, 90.0}, */
- {240.0, 360.0, 180.0},
- {90.0, 180.0, 90.0},
-
- {11.9, 0.0, -18.4},
- {11.9, 0.0, -18.4},
- {11.9, 0.0, -18.4},
- {11.9, 0.0, -18.4},
- {11.9, 0.0, -18.4},
- };
-
-
- vector view_from_ctl[] = {
-
- {-1.0, 1.0, -4.0},
-
- {-1.0, -3.0, -4.0}, /* 0 */
- {-3.0, 1.0, -3.0}, /* 1 */
-
- {-1.8, 2.0, 5.4}, /* 2 */
- {-0.4, 2.0, 1.2}, /* 3 */
- {-0.2, 1.5, 0.6}, /* 4 */
- {-0.2, 1.2, 0.6}, /* 5 */
-
- {-0.8, 1.0, 2.4}, /* 6 */
- {-1.0, 2.0, 3.0}, /* 7 */
- {0.0, 4.0, 3.6}, /* 8 */
- {-0.8, 4.0, 1.2}, /* 9 */
-
- {-0.2, 3.0, 0.6}, /* 10 */
- {-0.1, 2.0, 0.3}, /* 11 */
- {-0.1, 2.0, 0.3}, /* 12 */
- {-0.1, 2.0, 0.3}, /* 13 */
- {-0.1, 2.0, 0.3}, /* 13 */
-
-
- };
-
- vector view_to_ctl[] = {
-
- {-1.0, 1.0, 0.0},
-
- {-1.0, -3.0, 0.0},
- {-1.0, 1.0, 0.0},
-
- {0.1, 0.0, -0.3},
- {0.1, 0.0, -0.3},
- {0.1, 0.0, -0.3},
- {0.0, 0.2, 0.0},
-
- {0.0, 0.6, 0.0},
- {0.0, 0.8, 0.0},
- {0.0, 0.8, 0.0},
- {0.0, 0.8, 0.0},
-
- {0.0, 0.8, 0.0},
- {0.0, 0.8, 0.0},
- {0.0, 0.8, 0.0},
- {0.0, 0.8, 0.0},
- {0.0, 0.8, 0.0},
-
- };
-
-
- vector view_from, view_to, light_pos, logo_pos, logo_rot;
-
- parameter *view_from_spline, *view_to_spline,
- *light_pos_spline, *logo_pos_spline,
- *logo_rot_spline;
-
- parameter *calc_spline_params(vector *, int);
-
- double a3, a4;
-
- void ideas_usage(void)
- {
- fprintf(stderr, "Usage: ideas [-a] [-m] [-d] -s{1-4}\n");
- fprintf(stderr, "Press ESC to quit, 1-4 to control speed, any other key\n");
- fprintf(stderr, "to pause.\n");
- }
-
- void main(int argc, char **argv)
- {
- float x, y, z, c;
- int pick;
- int i;
- int auto_run; /* If set, then automatically run forever */
- struct timeval start;
- struct timeval current;
- float timediff;
- float timeoffset; /* Used to compute timing */
- float new_speed; /* Set new animation speed? */
- int resetclock; /* Reset the clock? */
- int timejerk; /* Set to indicate time jerked! (menu pulled down) */
- int paused = 0; /* Paused? */
- int right = 0; /* Draw right eye? */
-
- XEvent event;
- char buffer[5];
- int bufsize = 5;
- KeySym key;
- XComposeStatus compose;
-
- /* .4 spline distance per second by default */
- move_speed = SPEED_MEDIUM;
- new_speed = SPEED_MEDIUM;
- timeoffset = START_TIME;
-
- auto_run = 0; /* Don't automatically run forever */
- for (i = 1; i < argc; i++) {
- if (argv[i][0] != '-') {
- break;
- }
-
- switch(argv[i][1]) {
- case 'a': /* Keep running forever */
- auto_run = 1;
- break;
- case 'm': /* Multisample */
- multisample = 1;
- break;
- case 'd': /* Single buffer */
- doublebuffer = 0;
- break;
- case 'S': /* Stereo mode */
- stereo = 1;
- break;
- case 's':
- switch(argv[i][2]) {
- case '1':
- move_speed = new_speed = SPEED_SLOW;
- break;
- case '2':
- move_speed = new_speed = SPEED_MEDIUM;
- break;
- case '3':
- move_speed = new_speed = SPEED_FAST;
- break;
- case '4':
- move_speed = new_speed = SPEED_SUPER_FAST;
- break;
- }
- break;
- default:
- ideas_usage();
- break;
- }
- }
-
- initialize(argv[0]);
-
- current_time = timeoffset;
- resetclock = 1;
- timejerk = 0;
- while (TRUE) {
- if ((current_time) > (TIME*1.0)-3.0) {
- if (auto_run) {
- hold_time += current_time - (TIME - 3.001);
- if (hold_time > 3.0) { /* 3 second hold */
- hold_time = 0.0;
- resetclock = 1;
- }
- }
- current_time = TIME*1.0-3.001;
- }
- while(XPending(dpy)) {
- XNextEvent(dpy, &event);
- switch(event.type) {
- case ConfigureNotify:
- resize_window();
- break;
- case ButtonPress:
- if (event.xbutton.button == 1) {
- resetclock = 1;
- paused = 0;
- }
- break;
- case KeyPress:
- XLookupString(&event.xkey, buffer, bufsize, &key, &compose);
- if (key == XK_Escape) exit(0);
- else if (key == XK_1 || key == XK_KP_1)
- new_speed = SPEED_SLOW;
- else if (key == XK_2 || key == XK_KP_2)
- new_speed = SPEED_MEDIUM;
- else if (key == XK_3 || key == XK_KP_3)
- new_speed = SPEED_FAST;
- else if (key == XK_4 || key == XK_KP_4)
- new_speed = SPEED_SUPER_FAST;
- else {
- if (paused) timejerk = 1;
- paused = ~paused;
- }
- break;
- }
- }
-
- if (stereo) {
- right = ~right;
- if (right) glDrawBuffer((doublebuffer) ? GL_BACK_RIGHT : GL_RIGHT);
- else glDrawBuffer((doublebuffer) ? GL_BACK_LEFT : GL_LEFT);
- }
-
- calc_spline(view_from, view_from_spline, current_time);
- calc_spline(view_to, view_to_spline, current_time);
- calc_spline(light_pos, light_pos_spline, current_time);
- calc_spline(logo_pos, logo_pos_spline, current_time);
- calc_spline(logo_rot, logo_rot_spline, current_time);
-
- tmplight[1] = light_pos[X] - logo_pos[X];
- tmplight[2] = light_pos[Y] - logo_pos[Y];
- tmplight[3] = light_pos[Z] - logo_pos[Z];
-
- glNewList(LIGHT_TMP, GL_COMPILE);
- glMaterialf(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, * tmplight);
- glEndList();
-
- tv[0][0] = tv[1][1] = tv[2][2] = light_pos[Y];
-
- glColor3ub(0, 0, 0);
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-
- /*
- * SHADOW
- */
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- gluLookAt(view_from[X], view_from[Y], view_from[Z],
- view_to[X], view_to[Y], view_to[Z],
- 0.0, 1.0, 0.0);
-
- if (view_from[Y] > 0.0) draw_table();
-
- glEnable(GL_CULL_FACE);
- glDisable(GL_DEPTH_TEST);
-
- if (logo_pos[Y] < 0.0) {
-
- if (logo_pos[Y]>-0.33) {
- /* We're emerging from the table */
- c = 1.0 - (logo_pos[Y]) / -0.33;
- pca /= 4.0;
- glColor3ub((int)(128.0*(1.0-c)*0.5 + 255.0*pca*c),
- (int)(102.0*(1.0-c)*0.5 + 255.0*pca*c),
- (int)(179.0*(1.0-c)*0.5 + 200.0*pca*c));
- } else {
- /* Still under table */
- glColor3ub(128/2, 102/2, 179/2);
- }
-
- glPushMatrix();
- glScalef(0.04, 0.0, 0.04);
- glRotatef(0.1 * (-900), 1.0, 0.0, 0.0);
- glRotatef(0.1 * ((int)(10.0*logo_rot[Z])), 0.0, 0.0, 1.0);
- glRotatef(0.1 * ((int)(10.0*logo_rot[Y])), 0.0, 1.0, 0.0);
- glRotatef(0.1 * ((int)(10.0*logo_rot[X])), 1.0, 0.0, 0.0);
- glRotatef(0.1 * (353), 1.0, 0.0, 0.0);
- glRotatef(0.1 * (450), 0.0, 1.0, 0.0);
- draw_logo_shadow();
- glPopMatrix();
- }
-
- if (logo_pos[Y] > 0.0) {
- glPushMatrix();
- if (logo_pos[Y]<0.33) {
- pca /= 4.0;
- c = 1.0 - (logo_pos[Y])/0.33;
- glColor3ub((int)(255.0*pca*c),
- (int)(255.0*pca*c),
- (int)(200.0*pca*c));
- } else {
- glColor3ub(0, 0, 0);
- }
-
- glTranslatef(light_pos[X], light_pos[Y], light_pos[Z]);
- glMultMatrixf(&tv[0][0]);
- glTranslatef(-light_pos[X]+logo_pos[X],
- -light_pos[Y]+logo_pos[Y],
- -light_pos[Z]+logo_pos[Z]);
- glScalef(0.04, 0.04, 0.04);
- glRotatef (0.1 * (-900), 1.0, 0.0, 0.0);
- glRotatef (0.1 * ((int)(10.0*logo_rot[Z])), 0.0, 0.0, 1.0);
- glRotatef (0.1 * ((int)(10.0*logo_rot[Y])), 0.0, 1.0, 0.0);
- glRotatef (0.1 * ((int)(10.0*logo_rot[X])), 1.0, 0.0, 0.0);
- glRotatef (0.1 * (353), 1.0, 0.0, 0.0);
- glRotatef (0.1 * (450), 0.0, 1.0, 0.0);
-
-
- glEnable(GL_POLYGON_STIPPLE);
- glPolygonStipple(stipple);
- draw_logo_shadow();
- glDisable(GL_POLYGON_STIPPLE);
- glPopMatrix();
- }
- /*
- * DONE SHADOW
- */
-
-
- glEnable(GL_DEPTH_TEST);
- glDisable(GL_CULL_FACE);
- glEnable(GL_LIGHTING);
-
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- gluPerspective(.1*(450), 5.0/4.0, 0.5, 20.0);
- glMatrixMode(GL_MODELVIEW);
- glLoadMatrixf(&idmat[0][0]);
-
- gluLookAt(view_from[X], view_from[Y], view_from[Z],
- view_to[X], view_to[Y], view_to[Z],
- 0.0, 1.0, 0.0);
-
- glCallList( MAT_HOLDER_RINGS);
- /* glEnable(GL_FRONT); */
-
- glPushMatrix();
- glTranslatef(light_pos[X], light_pos[Y], light_pos[Z]);
- glScalef(0.1, 0.1, 0.1);
-
- x = light_pos[X] - logo_pos[X];
- y = light_pos[Y] - logo_pos[Y];
- z = light_pos[Z] - logo_pos[Z];
-
- if (x!=0.0) {
- a3 = -atan2(z, x)*10.0 RAD;
- } else a3 = 0.0;
-
- a4 = -atan2(sqrt(x*x + z*z), y)*10.0 RAD;
-
- glRotatef (0.1 * ((int)a3), 0.0, 1.0, 0.0);
- glRotatef (0.1 * ((int)a4), 0.0, 0.0, 1.0);
- glRotatef (0.1 * (-900), 1.0, 0.0, 0.0);
-
- glEnable(GL_LIGHT2);
- glEnable(GL_LIGHT3);
- glCallList(MAT_HEMISPHERE);
- glEnable(GL_NORMALIZE);
- draw_hemisphere();
- glDisable(GL_NORMALIZE);
- glPopMatrix();
-
- glDisable(GL_LIGHT2);
- glDisable(GL_LIGHT3);
- glEnable(GL_LIGHT1);
- glLightfv(GL_LIGHT1, GL_POSITION, light_pos);
-
- if (logo_pos[Y] > -0.33) {
-
- glCallList(MAT_LOGO);
-
- glPushMatrix();
- glTranslatef(logo_pos[X], logo_pos[Y], logo_pos[Z]);
- glScalef(0.04, 0.04, 0.04);
- glRotatef (0.1 * (-900), 1.0, 0.0, 0.0);
- glRotatef (0.1 * ((int)(10.0*logo_rot[Z])), 0.0, 0.0, 1.0);
- glRotatef (0.1 * ((int)(10.0*logo_rot[Y])), 0.0, 1.0, 0.0);
- glRotatef (0.1 * ((int)(10.0*logo_rot[X])), 1.0, 0.0, 0.0);
- glRotatef (0.1 * (353), 1.0, 0.0, 0.0);
- glRotatef (0.1 * (450), 0.0, 1.0, 0.0);
- glEnable(GL_LIGHTING);
- draw_logo();
- glPopMatrix();
- }
-
- if (view_from[Y] < 0.0) draw_under_table();
-
- glXSwapBuffers(dpy, window);
-
- /* Time jerked -- adjust clock appropriately */
- if (timejerk) {
- timejerk = 0;
- timeoffset = current_time;
- gettimeofday(&start, NULL);
- }
-
- /* Reset our timer */
- if (resetclock) {
- resetclock = 0;
- paused = 0;
- timeoffset = START_TIME;
- gettimeofday(&start, NULL);
- }
-
- /* Compute new time */
- gettimeofday(¤t, NULL);
- timediff = (current.tv_sec - start.tv_sec) +
- (current.tv_usec - start.tv_usec) / 1000000.0;
- if (!paused) current_time = timediff * move_speed + timeoffset;
-
- /* Adjust to new speed */
- if (new_speed != move_speed) {
- move_speed = new_speed;
- timeoffset = current_time;
- gettimeofday(&start, NULL);
- }
- }
- }
-
- static Bool WaitForMapNotify(Display *d, XEvent *e, char *arg)
- {
- if ((e->type == MapNotify) && (e->xmap.window == (Window)arg)) {
- return GL_TRUE;
- }
- return GL_FALSE;
- }
-
- void resize_window()
- {
- XWindowAttributes windowattr;
-
- XGetWindowAttributes(dpy, window, &windowattr);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- gluPerspective (45.0, 5.0/4.0, 0.5, 20.0);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- glViewport(0, 0, windowattr.width, windowattr.height);
- }
-
- void initialize(char *title)
- {
- char *t, *strrchr();
- int multiAvail;
- int can_ogl, can_zbuffer, can_rgba;
-
- XVisualInfo *vi;
- XSetWindowAttributes swa;
- XSizeHints hints;
- XEvent ev;
- GLXContext cx;
- int *attr;
-
- dpy = XOpenDisplay(0);
- if (dpy == NULL) {
- fprintf(stderr, "Can't connect to display \"%s\"\n", getenv("DISPLAY"));
- exit(1);
- }
-
- attr = doublebuffer ?
- (stereo ? RGBA_DB_ST_attributes : RGBA_DB_attributes) :
- (stereo ? RGBA_SB_ST_attributes : RGBA_SB_attributes);
- vi = glXChooseVisual(dpy, DefaultScreen(dpy), attr);
- if (vi == NULL && stereo) {
- fprintf(stderr, "Unable to find stereo visual.\n");
- stereo = 0;
- attr = doublebuffer ? RGBA_DB_attributes : RGBA_SB_attributes;
- vi = glXChooseVisual(dpy, DefaultScreen(dpy), attr);
- }
- if (vi == NULL) {
- fprintf(stderr, "No matching visual on \"%s\"\n",
- getenv("DISPLAY"));
- exit(1);
- }
-
- glXGetConfig(dpy, vi, GLX_USE_GL, &can_ogl);
- if (!can_ogl) {
- system("inform 'Your system must support OpenGL to run ideas'");
- exit(1);
- }
- glXGetConfig(dpy, vi, GLX_RGBA, &can_rgba);
- if (!can_rgba) {
- system("inform 'Your system must support RGB mode to run ideas'");
- exit(1);
- }
- glXGetConfig(dpy, vi, GLX_DEPTH_SIZE, &can_zbuffer);
- if (can_zbuffer == 0) {
- system("inform 'Your system must have a z-buffer to run ideas'");
- exit(1);
- }
- swa.border_pixel = 0;
- swa.colormap = XCreateColormap(dpy, RootWindow(dpy, vi->screen),
- vi->visual, AllocNone);
- swa.event_mask = ExposureMask | StructureNotifyMask | KeyPressMask |
- ButtonPressMask;
- window = XCreateWindow(dpy, RootWindow(dpy, vi->screen), 10, 10, 50, 50,
- 0, vi->depth, InputOutput, vi->visual,
- CWBorderPixel | CWColormap | CWEventMask, &swa);
- XStoreName(dpy, window, "Ideas");
-
- hints.width = 500;
- hints.height = 400;
- hints.min_aspect.x = 5;
- hints.min_aspect.y = 4;
- hints.max_aspect.x = 5;
- hints.max_aspect.y = 4;
- hints.flags = PSize | PAspect;
- XSetNormalHints(dpy, window, &hints);
-
- XMapWindow(dpy, window);
- XIfEvent(dpy, &ev, WaitForMapNotify, (char *)window);
-
- cx = glXCreateContext(dpy, vi, 0, GL_TRUE);
- if (!glXMakeCurrent(dpy, window, cx)) {
- fprintf(stderr, "Can't make window current to context\n");
- exit(1);
- }
-
- if (multisample) glEnable(GL_POLYGON_SMOOTH);
-
- init_lights();
- init_materials();
-
- build_table();
-
- view_from_spline = calc_spline_params(view_from_ctl, TIME);
- view_to_spline = calc_spline_params(view_to_ctl, TIME);
- light_pos_spline = calc_spline_params(light_pos_ctl, TIME);
- logo_pos_spline = calc_spline_params(logo_pos_ctl, TIME);
- logo_rot_spline = calc_spline_params(logo_rot_ctl, TIME);
-
- resize_window();
-
- glMatrixMode(GL_MODELVIEW);
- }
-
-
- void build_table()
- {
- float i, j;
-
- for (j=0.0; j<=TABLERES*1.0; j+=1.0) {
- for (i=0.0; i<=TABLERES*1.0; i+=1.0) {
- table_points[(int)j][(int)i][Z] = (i-TABLERES*1.0/2.0)/2.0;
- table_points[(int)j][(int)i][X] = (j-TABLERES*1.0/2.0)/2.0;
- table_points[(int)j][(int)i][Y] = 0.0;
- }
- }
- }
-
-
- void draw_table()
- {
-
- float x, z, c;
- int i, j;
- int k, l;
- float m, n;
- float ov[3], lv[3];
-
- glDisable(GL_DEPTH_TEST);
- glDisable(GL_LIGHTING);
-
- ov[X] = light_pos[X]-logo_pos[X];
- ov[Y] = light_pos[Y]-logo_pos[Y];
- ov[Z] = light_pos[Z]-logo_pos[Z];
-
- normalize(ov);
-
- for (j=0; j<=TABLERES; j++) {
- for (i=0; i<=TABLERES; i++) {
- lv[X] = light_pos[X] - table_points[j][i][X];
- lv[Y] = light_pos[Y] - table_points[j][i][Y];
- lv[Z] = light_pos[Z] - table_points[j][i][Z];
- normalize(lv);
- if ((c = dot(lv, ov))<0.0) c = 0.0;
- c = c * c * c * lv[Y] * 255.0;
- /* fade */
- if ((current_time>TIME-5.0) && (current_time<TIME-3.0))
- c *= 1.0 - (current_time-(TIME-5.0)) * 0.5;
-
- tablecolors[j][i] = (int)c;
- }
- }
-
-
- for (l=0; l<TABLERES; l++) {
-
- glBegin(GL_TRIANGLE_STRIP);
- for (k=0; k<=TABLERES; k++) {
- glColor3ub(tablecolors[l][k],
- tablecolors[l][k],
- tablecolors[l][k]);
- glVertex3fv(table_points[l][k]);
-
- glColor3ub(tablecolors[l+1][k],
- tablecolors[l+1][k],
- tablecolors[l+1][k]);
- glVertex3fv(table_points[l+1][k]);
-
- }
- glEnd();
- }
-
- if (logo_pos[Y]>-0.33 && logo_pos[Y]<0.33) {
- glEnable(GL_DEPTH_TEST);
- }
-
- pca = 0.0;
- glBegin(GL_POLYGON);
- for (i=0; i<4; i++) {
- lv[X] = light_pos[X] - paper_points[i][X];
- lv[Y] = light_pos[Y] - paper_points[i][Y];
- lv[Z] = light_pos[Z] - paper_points[i][Z];
- normalize(lv);
- if ((c = dot(lv, ov))<0.0) c = 0.0;
- c = c * c * c * lv[Y];
- /* fade */
- if ((current_time>TIME-5.0) && (current_time<TIME-3.0))
- c *= 1.0 - (current_time-(TIME-5.0)) * 0.5;
-
- pcr = c * 255; pcg = c * 255; pcb = c * 200;
- pca += c;
- glColor3ub((int)pcr, (int)pcg, (int)pcb);
- glVertex3fv(paper_points[i]);
- }
- glEnd();
-
- glPushMatrix();
- glRotatef (0.1 * (-184), 0.0, 1.0, 0.0);
- glTranslatef(-0.3, 0.0, -0.8);
- glRotatef (0.1 * (-900), 1.0, 0.0, 0.0);
- glScalef(0.015, 0.015, 0.015);
-
-
- if (current_time>TIME*1.0-5.0) {
- c = (current_time-(TIME*1.0-5.0))/2.0;
- glColor3ub((int)(c*255.0), (int)(c*255.0), (int)(c*255.0));
- } else glColor3ub(0, 0, 0);
-
- glDisable(GL_DEPTH_TEST);
-
- draw_i();
- glTranslatef(3.0, 0.0, 0.0);
-
- draw_d();
- glTranslatef(6.0, 0.0, 0.0);
-
- draw_e();
- glTranslatef(5.0, 0.0, 0.0);
-
- draw_a();
- glTranslatef(6.0, 0.0, 0.0);
-
- draw_s();
- glTranslatef(10.0, 0.0, 0.0);
-
- draw_i();
- glTranslatef(3.0, 0.0, 0.0);
-
- draw_n();
- glTranslatef(-31.0, -13.0, 0.0);
-
- draw_m();
- glTranslatef(10.0, 0.0, 0.0);
-
- draw_o();
- glTranslatef(5.0, 0.0, 0.0);
-
- draw_t();
- glTranslatef(4.0, 0.0, 0.0);
-
- draw_i();
- glTranslatef(3.5, 0.0, 0.0);
-
- draw_o();
- glTranslatef(5.0, 0.0, 0.0);
-
- draw_n();
-
- glPopMatrix();
-
- }
-
-
-
- void draw_under_table()
- {
- int k, l;
-
- if(FALSE) glEnable(GL_DEPTH_TEST); else glDisable(GL_DEPTH_TEST);
-
-
- glColor3ub(0, 0, 0);
-
- for (l=0; l<TABLERES; l++) {
-
- glBegin(GL_TRIANGLE_STRIP);
- for (k=0; k<=TABLERES; k++) {
-
- glVertex3fv(table_points[l][k]);
- glVertex3fv(table_points[l+1][k]);
-
- }
- glEnd();
- }
-
- if(TRUE) glEnable(GL_DEPTH_TEST); else glDisable(GL_DEPTH_TEST);
-
- }
-
-
-
- void calc_spline(vector v, parameter *params, float current_time)
- {
-
- float t, tt;
- int i, j;
-
- tt = t = current_time - (float)((int)current_time);
-
- for (i=0; i<3; i++) {
-
-
- v[i] = params[(int)current_time][3][i] +
- params[(int)current_time][2][i] * t +
- params[(int)current_time][1][i] * t * t +
- params[(int)current_time][0][i] * t * t * t;
- }
-
- }
-
-
- parameter *calc_spline_params(vector *ctl_pts, int n)
- {
-
- int i, j;
- parameter *params;
-
- if (n<4) {
- fprintf(stderr,
- "calc_spline_params: not enough control points\n");
- return (NULL);
- }
-
- params = (parameter *)malloc(sizeof(parameter) * (n-3));
-
- for (i=0; i<n-3; i++) {
-
- for (j=0; j<3; j++) {
-
- params[i][3][j] = ctl_pts[i+1][j];
- params[i][2][j] = ctl_pts[i+2][j] - ctl_pts[i][j];
- params[i][1][j] = 2.0 * ctl_pts[i][j] +
- -2.0 * ctl_pts[i+1][j] +
- 1.0 * ctl_pts[i+2][j] +
- -1.0 * ctl_pts[i+3][j];
- params[i][0][j] = -1.0 * ctl_pts[i][j] +
- 1.0 * ctl_pts[i+1][j] +
- -1.0 * ctl_pts[i+2][j] +
- 1.0 * ctl_pts[i+3][j];
-
- }
- }
-
- return (params);
- }
-
-
- void normalize(vector v)
- {
- float r;
-
- r = sqrt(v[X]*v[X] + v[Y]*v[Y] + v[Z]*v[Z]);
-
- v[X] /= r;
- v[Y] /= r;
- v[Z] /= r;
- }
-
-
- float dot(vector v1, vector v2)
- {
- return v1[X]*v2[X]+v1[Y]*v2[Y]+v1[Z]*v2[Z];
- }
-
-